import 'package:flutter/material.dart';
import 'package:syria_sports/core/app_export.dart';

import '../models/home_model.dart';

class ExerciseSelectionWidget extends StatelessWidget {
  final List<FluffyGym> gyms;
  final Function(GymExercise)? onExerciseSelected;

  const ExerciseSelectionWidget({super.key,
    required this.gyms,
    this.onExerciseSelected,
  });

  @override
  Widget build(BuildContext context) {
    return SizedBox(
      height: MediaQuery.of(context).size.height/2.5,
      width:  MediaQuery.of(context).size.width,
      child: ListView.builder(
        itemCount: gyms.length,
        itemBuilder: (context, index) {
          final gym = gyms[index];
          return ExpansionTile(
            iconColor: Colors.orange,
            collapsedIconColor: Colors.red,
            title: Text(gym.name),
            subtitle: Text('${gym.exercises.length} تمرين', style: theme.textTheme.bodySmall,),
            children: gym.exercises.map((exercise) {
              return ListTile(
                leading: CircleAvatar(radius: 4,backgroundColor: Colors.deepOrange,),
                title: Text(exercise.name),
                onTap: () {
                  if (onExerciseSelected != null) {
                    onExerciseSelected!(exercise);
                  }
                },
              );
            }).toList(),
          );
        },
      ),
    );
  }
}